package run;

import com.SpringApplications;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.jwt.JwtDecoderFactory;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import utils.Utils;

import java.util.List;

@Slf4j
@SpringBootTest(classes = {SecurityDemo.Dummy.class},
        webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class SecurityDemo {
    Object lock = new Object();
    @Autowired
    Environment environment;
    @Autowired
    GenericApplicationContext beanFactory;

    @Test
    public void verify() throws InterruptedException {

        Utils.print(beanFactory);
        JwtDecoder bean = beanFactory.getBean(JwtDecoder.class);
                                                // spring.security.oauth2.resourceserver.jwt.jwk-set-uri
        String property = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
        log.info("{}",property);

        synchronized (lock){
            lock.wait();;
        }
    }
    @Import(SpringApplications.class)
    @Configuration
    @EnableAutoConfiguration
    public  static class Dummy{

    }
}
